﻿@model KPIS.GERP.Models.ICM.BidderQuotation
@{
    int i = ViewBag.I;
    var m = Model;
}
 @{
    var ExcludeVatAmount = (m.RemainQty ?? 0)*(m.Price ?? 0);
     <div class="Example_Q">  
         <table border="0" style="width: 99%" cellpadding="0" cellspacing="1px"> 
             <tr>
                 <td class="caption1">
                     สินค้า/บริการ
                 </td>
                 <td colspan="100%" class="controls-detail">
                     <strong>
                         @(m.PurchaseRequestItem.ResItemId != null ? m.PurchaseRequestItem.MasResourceItem.Name : m.PurchaseRequestItem.MasBudgetExpense.Name)
                     </strong>
                     @(string.IsNullOrWhiteSpace(m.Descr) ? "" : " - " + m.Descr)
                     <span style="float: right">@(i++) / @(ViewBag.Count)</span>
                 </td>
             </tr> 
             <tr>
                 <td class="caption1">
                     จำนวนที่สั่ง
                 </td>
                 <td class="controls-detail">
                     @Html.DisplayFor(model => m.Qty) @Html.DisplayFor(model => m.PurchaseRequestItem.MasResourceItem.MasUnit.Name)
                 </td>
                 <td class="caption1">
                     เหลือยังไม่ตรวจรับ
                 </td>
                 <td class="controls-detail"> 
                     @Html.DisplayFor(model => m.RemainQty) @Html.DisplayFor(model => m.PurchaseRequestItem.MasResourceItem.MasUnit.Name)
                 </td>
                 <td class="caption1">จำนวนเงินคงเหลือ	</td>
                 <td class="controls-detail">@Html.DisplayFor(model => m.RemainAmount) บาท</td>
             </tr>
            
             <tr>
                 <td class="caption1">จำนวนที่รับในงวด</td>
                 <td class="controls-detail">                     @Html.TextBox("Qty_" + m.BidderQuoId, m.RemainQty, new { @class = "aSpinEdit2", data_placeholder = "จำนวนที่รับ", step = "any", min = 0, id = "Qty_" + m.BidderQuoId })</td>
                 <td class="caption1">ราคาต่อหน่วย</td>
                 <td class="controls-detail">@Html.TextBox("Price_" + m.BidderQuoId, m.Price, new {@class = "aSpinEdit", data_placeholder = "ราคาต่อหน่วยไม่รวม Vat", step = "any", min = 0, id = "Price_" + m.BidderQuoId})</td>
                 <td class="caption1">ราคาไม่รวม Vat</td>
                 <td class="controls-detail">@Html.TextBox("ExcludeVatAmount_" + m.BidderQuoId, ExcludeVatAmount, new {@class = "aSpinEdit", data_placeholder = "จำนวนเงินไม่รวม Vat", step = "any", min = 0, max = m.ExcludeVatAmount, id = "ExcludeVatAmount_" + m.BidderQuoId})</td>
             </tr>
             <tr>
                 <td class="caption1">% ส่วนลด</td>
                 <td class="controls-detail">@Html.TextBox("DiscountPercent_" + m.BidderQuoId, m.DiscountPercent, new {@class = "aSpinEdit", data_placeholder = "% ส่วนลด", step = "any", min = 0, id = "DiscountPercent_" + m.BidderQuoId})</td>
                 <td class="caption1">ส่วนลดพิเศษ</td>
                 <td class="controls-detail">@Html.TextBox("ExtraDiscount_" + m.BidderQuoId, m.ExtraDiscount, new {@class = "aSpinEdit", data_placeholder = "ส่วนลดพิเศษ", step = "any", min = 0, id = "ExtraDiscount_" + m.BidderQuoId})</td>
                 <td class="caption1">% Vat</td>
                 @{
                     decimal vatAmount = m.VatAmount ?? 0;
                     decimal excludeVatAmount = m.ExcludeVatAmount ?? 0;
                     decimal vatPercent = excludeVatAmount == 0 ? 0 : (vatAmount/excludeVatAmount) * 100;
                 }
                 <td class="controls-detail">@Html.TextBox("VatPercent_" + m.BidderQuoId, vatPercent, new { @class = "aSpinEdit", data_placeholder = "% Vat", step = "any", min = 0, max = 100, id = "VatPercent_" + m.BidderQuoId })</td>
             </tr> 
             <tr>
                 <td class="caption1">Vat (บาท)</td>
                 <td class="controls-detail">@Html.TextBox("VatAmount_" + m.BidderQuoId, m.VatAmount, new {@class = "aSpinEdit", data_placeholder = "จำนวนเงินไม่รวม Vat", step = "any", min = 0, max = m.ExcludeVatAmount, id = "VatAmount_" + m.BidderQuoId})</td>
                 <td class="caption1">ราคาสุทธิ</td>
                 <td class="controls-detail">@Html.TextBox("NetAmount_" + m.BidderQuoId, m.RemainAmount, new { @class = "aSpinEdit", data_placeholder = "จำนวนเงินไม่รวม Vat", step = "any", min = 0, id = "NetAmount_" + m.BidderQuoId })</td>
                 <td>
                     <img src="~/Content/Images/Icon/cal_icon.png" title="คลิกเพื่อคำนวน"
                          style="cursor: pointer" id="calculateIcon_@m.BidderQuoId"  /></td>
             </tr>
             
         </table>
     </div>

}
        
        
        
 
@*<tr>
    <td>
        @(Model.PurchaseRequestItem.ResItemId != null ? Model.PurchaseRequestItem.MasResourceItem.Name : Model.PurchaseRequestItem.MasBudgetExpense.Name)
    </td>
    <td>
        @Html.DisplayFor(model => model.Descr)
    </td>
    <td style="text-align: right">
        @Html.DisplayFor(model => model.Qty)
    </td>
    <td style="text-align: right">
        @Html.TextBox("Qty_" + Model.BidderQuoId, Model.RemainQty, new { @class = "aSpinEdit", data_placeholder = "จำนวนที่รับ", step = "any", min = 0, id = "Qty_" + Model.BidderQuoId }) 
    </td>
    <td style="text-align: right"> 
        @Html.TextBox("Price_" + Model.BidderQuoId, Model.Price, new { @class = "aSpinEdit", data_placeholder = "ราคาต่อหน่วยไม่รวม Vat", step = "any", min = 0, id = "Price_" + Model.BidderQuoId })
    </td>
    @{
                                                var ExcludeVatAmount = (Model.RemainQty ?? 0) * (Model.Price ?? 0);
    }
    <td style="text-align: right">
        @Html.TextBox("ExcludeVatAmount_" + Model.BidderQuoId, ExcludeVatAmount, new { @class = "aSpinEdit", data_placeholder = "จำนวนเงินไม่รวม Vat", step = "any", min = 0, max = Model.ExcludeVatAmount, id = "ExcludeVatAmount_" + Model.BidderQuoId })
    </td>
    <td style="text-align: right">
        @Html.TextBox("DiscountPercent_" + Model.BidderQuoId, Model.DiscountPercent, new { @class = "aSpinEdit", data_placeholder = "% ส่วนลด", step = "any", min = 0, id = "DiscountPercent_" + Model.BidderQuoId })
    </td>
    <td style="text-align: right">
        @Html.TextBox("ExtraDiscount_" + Model.BidderQuoId, Model.ExtraDiscount, new { @class = "aSpinEdit", data_placeholder = "ส่วนลดพิเศษ", step = "any", min = 0, id = "ExtraDiscount_" + Model.BidderQuoId })
    </td>
    <td style="text-align: right">
        @Html.TextBox("VatPercent_" + Model.BidderQuoId, 7, new { @class = "aSpinEdit", data_placeholder = "% Vat", step = "any", min = 0, max = 100, id = "VatPercent_" + Model.BidderQuoId })
    </td>
    @{
                                                ExcludeVatAmount = ExcludeVatAmount - (ExcludeVatAmount * (Model.DiscountPercent ?? 0) / 100) - (Model.ExtraDiscount ?? 0);
                                                var VatAmount = ExcludeVatAmount * 7 / 100;
    }
    <td style="text-align: right">
        @Html.TextBox("VatAmount_" + Model.BidderQuoId, VatAmount, new { @class = "aSpinEdit", data_placeholder = "จำนวนเงินไม่รวม Vat", step = "any", min = 0, max = Model.ExcludeVatAmount, id = "VatAmount_" + Model.BidderQuoId })
    </td>
    <td style="text-align: right">
        @Html.TextBox("NetAmount_" + Model.BidderQuoId, ExcludeVatAmount + VatAmount, new { @class = "aSpinEdit", data_placeholder = "จำนวนเงินไม่รวม Vat", step = "any", min = 0, id = "NetAmount_" + Model.BidderQuoId })
    </td>
    <td style="text-align: right">
        @Html.DisplayFor(model => model.RemainAmount)
    </td>
    <td style="text-align: right">
        @Html.DisplayFor(model => model.RemainQty)
    </td>
</tr>*@
                                    